<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>组件使用中的细节点-3</title>
  <script src="../asset/js/vue.js"></script>
</head>

<body>
  <div id="root">
    <counter ref='one' @change='handleChange'></counter>
    <counter ref='two' @change='handleChange'></counter>
    <div>总计：{{total}}</div>
  </div>
  <script>
    Vue.component('counter', {
      template: '<button @click="handleClick">{{number}}</button>',
      data() {
        return {
          number: 0
        }
      },
      methods: {
        handleClick() {
          this.number++
            this.$emit('change') //向外界传值
        }
      }
    })
    let vm = new Vue({
      el: '#root', //vue接管的区域
      data: {
        total: 0
      },
      methods: {
        handleChange() {
          this.total = this.$refs.one.number + this.$refs.two.number
        }
      }
    })
  </script>
</body>

</html>